from google.appengine.api import users
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app


class MainPage(webapp.RequestHandler):
    def get(self):
        user = users.get_current_user()
        if user:
            greeting = ("Welcome, %s! (<a href=\"%s\">sign out</a>)" %
                        (user.nickname(), users.create_logout_url("/")))
#            self.response.out.write(
#                'Hello %s <a href="%s">Sign out</a><br>Is administrator: %s' %
#                (user.nickname(), users.create_logout_url("/"), users.is_current_user_admin())
#            )
        else:
            greeting = ("<a href=\"%s\">Sign in or register</a>." %
                        users.create_login_url("/"))

#            self.redirect(users.create_login_url(self.request.uri))
        self.response.out.write(greeting)


application = webapp.WSGIApplication([('/', MainPage)], debug = True)

def main():
    run_wsgi_app(application)

if __name__ == "__main__":
    main()

